﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class RC_WaitingListForPlacement : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        private IEmployeeTypeBLL etBLL = new EmployeeTypeBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            IncludeJava();

            if (!IsPostBack)
            {
                bindEmpType();
                BindStatusCombo();
                BindEntryTypeCombo();
                LoadDataGrid();
            }
            
        }
        public void IncludeJava()
        {
            HtmlGenericControl script = new HtmlGenericControl();
            script.TagName = "script";
            script.Attributes.Add("type", "text/javascript");
            script.Attributes.Add("src", "../../Scripts/jsfunction.js");
            Page.Header.Controls.Add(script);
        }
        private void bindEmpType()
        {
            IList<EmployeeTypeInfo> infoList = etBLL.ListEmployeeTypes();

            employeeTypeCombo.DataSource = infoList;
            employeeTypeCombo.DataBind();              
        }

        private void BindStatusCombo()
        {
           DataTable dt;
           WaitingListForPlacementBLL obj = new WaitingListForPlacementBLL();

           dt = obj.SelectStatusCombo();

           statusCombo.DataValueField = "emp_status_seq";
           statusCombo.DataTextField = "emp_status_name";
           statusCombo.DataSource = dt;
           statusCombo.DataBind();  
             
        }

        private void BindEntryTypeCombo()
        {
           DataTable dt;
           WaitingListForPlacementBLL obj = new WaitingListForPlacementBLL();

           dt = obj.SelectEntryTypeCombo(); 
           entryTypeCombo.DataSource = dt;
           entryTypeCombo.DataBind();  
            
        }

        private void LoadDataGrid()
        {
            try
            {
                DataTable dt;
                WaitingListForPlacementBLL obj = new WaitingListForPlacementBLL();
                //ScoreSubBLL obj = new ScoreSubBLL();
                dt = obj.Select((int?)null
                    , statusCombo.SelectedValue.Length > 0 ? Int32.Parse(statusCombo.SelectedValue) : (int?)null
                    , employeeTypeCombo.SelectedValue.Length > 0 ? Int32.Parse(employeeTypeCombo.SelectedValue) : (int?)null
                    , entryTypeCombo.SelectedValue.Length > 0 ? Int32.Parse(entryTypeCombo.SelectedValue) : (int?)null
                    );
             
                RadGrid2.DataSource = dt;
                RadGrid2.DataBind();
            }
            catch (Exception ex)
            {

            }
        }

        protected void RadGrid2_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == "btnClick")
            {
                return;
            }
            
            if (e.CommandName == "Delete")
            {
                int seq = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["tmp_emp_seq"]);
       
                WaitingListForPlacementBLL obj = new WaitingListForPlacementBLL();
                obj.Delete(seq, ssMng.EmpSeqI);
            }
            LoadDataGrid();
        }

        protected void employeeTypeCombo_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            Session["EMPTYPE"] = employeeTypeCombo.SelectedValue;
            LoadDataGrid();
        }

        protected void statusCombo_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            LoadDataGrid();
        }

        protected void entryTypeCombo_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            Session["EntTypeSeq"] = entryTypeCombo.SelectedValue;

            LoadDataGrid();
        }

    }
}
